﻿using System;
using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;

using Close.Controls;
using Close.Properties;
using Close.Classes;

namespace Close
{
    //TODO: spolecne z GamesPanel a LevelsPanel dat to nove vytvoreneho predka
    class GamesPanel : FluidPanel
    {
        private FluidHeader header = new FluidHeader();
        private LevelListBox listBox = new LevelListBox();
        ThemeClass themeClass = ThemeClass.Settings;

        private int _level = 0;
        
        public GamesPanel(int level)
            : base()
        {
            _level = level;
        }

        protected override void InitControl()
        {
            base.InitControl();
            //Bounds = new Rectangle(0, 0, 240, 300);
            BackColor = Color.Black;
            Anchor = AnchorAll;
            const int h = 32;
            header.Bounds = new Rectangle(0, 0, themeClass.DisplayWidth, h);
            listBox.Bounds = new Rectangle(0, h, themeClass.DisplayWidth, themeClass.DisplayHeight - h); header.Anchor = AnchorTLR;
            listBox.Anchor = AnchorAll;
            header.BackButton.Shape = ButtonShape.Rounded;
            header.BackButton.Text = Resources.GameMnuBack;
            header.BackButton.Visible = true;
            header.Title = Resources.GameMnuTitle;
            header.BackButton.Click += new EventHandler(BackButton_Click);

            listBox.ItemClick += new EventHandler<ListBoxItemEventArgs>(listBox_ItemClick); 

            Controls.Add(header);
            Controls.Add(listBox);

        }

        public void BindData()
        {
            Data.GameDatabase data = Data.GameDatabase.GamesData;
            listBox.DataSource = data.GetGamesInLevel(_level);
        }

        public event EventHandler<EventArgs> ButtonBackClicked;
        void BackButton_Click(object sender, EventArgs e)
        {
            if (ButtonBackClicked != null)
            {
                ButtonBackClicked(this, e);
            }
        }

        /// <summary>
        /// Occurs when an item was clicked.
        /// </summary>
        public event EventHandler<ListBoxItemEventArgs> ItemClick;
        void listBox_ItemClick(object sender, ListBoxItemEventArgs e)
        {
            if (ItemClick != null)
            {
                ItemClick(this, e);
            }
        }

        public String SelectedText
        {
            get
            {
                return listBox.SelectedText;
            }
        }
        public LevelListBoxItem SelectedItem
        {
            get
            {
                return listBox.Item;
            }
        }
        public int SelectedIndex
        {
            get
            {
                return listBox.SelectedItemIndex;
            }
        }

    }
}
